//
//  MovieTableViewController.m
//  UI14_HomeWork_豆瓣
//
//  Created by Bodi on 16/6/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MovieTableViewController.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"
#define kWidth self.contentView.frame.size.width
#define kHight self.contentView.frame.size.height
@interface MovieTableViewController ()
@property (nonatomic, retain) UIImageView *movieImageView;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *idLabel;
@end

@implementation MovieTableViewController
- (void)dealloc{
    //    [_cellModel release];
    [_movieImageView release];
    [_nameLabel release];
    [_idLabel release];
    [_cellModel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //只对属性进行创建
        self.movieImageView = [[UIImageView alloc]init];
        /* 把子视图添加到contenView上 */
        [self.contentView addSubview:_movieImageView];
        [_movieImageView release];
        
        self.nameLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.idLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_idLabel];
        [_idLabel release];
        
    }
    return self;
    
}
- (void)layoutSubviews{
    //调用父类方法
    [super layoutSubviews];
    /* 对视图属性进行设置 **/
    UIImage *image = [UIImage imageNamed:@"bg_eventlistcell"];
    UIImageView *view = [[UIImageView alloc]initWithImage:image];
    view.frame = CGRectMake(20, 0, CGRectGetWidth(self.bounds) - 40, kHight - 20);
    
    [self.contentView addSubview:view];
    self.movieImageView.frame = CGRectMake(30, 10, kWidth * 0.3 - 20, kHight - 40);
    self.movieImageView.backgroundColor = [UIColor orangeColor];
    
    [self.contentView addSubview:self.movieImageView];
    // nameLabel
    self.nameLabel.frame = CGRectMake(_movieImageView.frame.size.width + 40, 60, kWidth * 0.5, kHight * 0.2 - 20);
    [self.contentView addSubview:self.nameLabel];
//    self.nameLabel.backgroundColor = [UIColor greenColor];
    
    // idLabel
//    self.idLabel.frame = CGRectMake(_nameLabel.frame.origin.x, kHight * 0.2 + 40, kWidth * 0.5, kHight * 0.2);
//    self.idLabel.backgroundColor = [UIColor blueColor];
    
}
/* 重写Model属性的setter方法 */
- (void)setCellModel:(MovieModel *)cellModel{
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
    }
    NSURL *url = [NSURL URLWithString:cellModel.pic_url];
    //    NSData *data = [NSData dataWithContentsOfURL:url];
    
    //    [_movieImageView sd_setImageWithURL:url];
    //    [_movieImageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    //
    //
    //    }];
    
    
    
    
    [_movieImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"abc1.jpg"]];
    //    _movieImageView.image = [UIImage imageWithData:data];
    _nameLabel.text = cellModel.movieName;
    _idLabel .text = cellModel.movieId;
    
    
    
}







@end
